# Maintainer: Martell Malone <martellmalone@gmail.com>

_realname=libgit2

pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")

#just comment out both pre defines to build stable release

_commit=ce5e661
_pre=rc2
__pre=-${_pre}

_pkgver=0.21.0

pkgver=${_pkgver}${_pre}
pkgrel=1
pkgdesc='A linkable library for Git (mingw-w64)'
arch=('any')
url='http://www.libgit2.github.com/'
license=('GPL2' 'custom')
source=("v${_pkgver}${__pre}.tar.gz::https://github.com/libgit2/libgit2/archive/")
md5sums=('SKIP')
options=('strip')
depends=("${MINGW_PACKAGE_PREFIX}-http-parser")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake" 'p7zip')

noextract=(v${_pkgver}${__pre}.tar.gz)

build() {
  
  plain "Extracting ${_realname}-${_pkgver}${__pre}.tar.gz due to git folder tag"
  #tar -xzf $startdir/${_realname}-${_pkgver}${__pre}.tar.gz -C $srcdir
  cp -r $startdir/v${_pkgver}${__pre}.tar.gz ${srcdir}
  cd ${srcdir}
  7z x ${srcdir}/v${_pkgver}${__pre}.tar.gz
  7z x ${srcdir}/v${_pkgver}${__pre}.tar

  rm -r ${srcdir}/v${_pkgver}${__pre}.tar.gz
  rm -r ${srcdir}/v${_pkgver}${__pre}.tar
  
  mkdir -p ${srcdir}/build-${MINGW_CHOST} 
  cd ${srcdir}/build-${MINGW_CHOST}
  
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX:PATH=${pkgdir}${MINGW_PREFIX} \
    ${srcdir}/${_realname}-${_pkgver}${__pre}

  make -j1
}


package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make -j1 install
}
